﻿// **********************************************
// SharePoint WebPart: UsersADBrowser
// Author: Khristoforov Yuri
// WWW   : http://usersadbrowser.codeplex.com, http://activex.net.ru
// **********************************************

using System;
using System.Data;
using System.ComponentModel;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.Caching;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Serialization;

using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using UsersADBrowser.Helpers;

namespace UsersADBrowser.WebParts
{
    public enum eUserLinkMode
    {
        DialogWindow,
        Page,
        ExternalPage
    }

    [XmlRoot(Namespace = "UsersADBrowser")]
    public class UsersADBrowserWP : WebPartTemplater
    {
        private const string _templateFileName = "Browser.ascx";
        private const string _templateDirName = "UsersADBrowser";
        private const string _resourceGlobalName = "UsersADBrowser";

        private XmlDataSource xmlOUTreeData;
        private TreeView tvOU;
        private DataGrid dgUserList;
        private CheckBox chSubTree;
        private TextBox txtSearch;
        private ImageButton btnSearch;
        private LinkButton btnExport;
        private PlaceHolder phSplitterCode;
        private Label lblTotalValue;
        private string strPathParam, strSearchQuery;
        private string _ldapStartPath = "", _ldapUsersFilter = "", _ldapProperties = "", _ldapSortProperty = "";
        private string _excludeOUs = "", _ldapLinkProperty = "", _externalPageUrl = "", _imageFormatUrl = "";
        private bool _isShowPhoto = false;
        private bool _isShowPresence = false;
        private bool _isSorting = false;
        private string[] _arrProps;
        private string[] _arrPropsInLower;
        private eViewMode _vewMode = eViewMode.Full;
        private eUserLinkMode _linkMode = eUserLinkMode.DialogWindow;
        private int _imageListWidth = 62;
        private int _cachingTimeOU = 120, _cachingTimeUserList = 120;

        public enum eViewMode
        {
            Full,
            UserList
        }

        [Browsable(true),
        Category("UsersADBrowser Parameters"),
        WebPartStorage(Storage.Shared),
        FriendlyName("LDAP Path start entry")]
        public string LDAPStartPath
        {
            get { return (_ldapStartPath == "" ? UsersADBrowserHelper.GetDefaultNamingContext() : _ldapStartPath); }
            set
            {
                if (value.ToUpper().IndexOf("DC=") == -1 && value != "" && value != null)
                    _ldapStartPath = UsersADBrowserHelper.FormatLdapEntry(value);
                else
                    _ldapStartPath = value;
            }
        }

        [Browsable(true),
        Category("UsersADBrowser Parameters"),
        WebPartStorage(Storage.Shared),
        FriendlyName("LDAP Users filter")]
        public string LDAPUsersFilter
        {
            get { return (_ldapUsersFilter == "" ? "(&(objectCategory=Person)(objectClass=User)(sn=*)(!userAccountControl:1.2.840.113556.1.4.803:=2))" : _ldapUsersFilter); }
            set { _ldapUsersFilter = value; }
        }

        [Browsable(true),
        Category("UsersADBrowser Parameters"),
        WebPartStorage(Storage.Shared),
        FriendlyName("AD user property attributes for user list (delimiter \",\")")]
        public string LDAPProperties
        {//for each attribute must be an entry in the resource file
            get { return (_ldapProperties == "" ? "sn,givenName,title,department,telephoneNumber,physicalDeliveryOfficeName,mail" : _ldapProperties); }
            set { _ldapProperties = value; }
        }

        [Browsable(true),
        Category("UsersADBrowser Parameters"),
        WebPartStorage(Storage.Shared),
        FriendlyName("AD user property attribute for sorting user list")]
        public string LDAPSortProperty
        {
            get { return (_ldapSortProperty == "" ? "sn" : _ldapSortProperty); }
            set { _ldapSortProperty = value; }
        }

        [Browsable(true),
        Category("UsersADBrowser Parameters"),
        WebPartStorage(Storage.Shared),
        FriendlyName("AD user property attribute for the link to a page with detailed info")]
        public string LDAPLinkProperty
        {
            get { return (_ldapLinkProperty == "" ? "sn" : _ldapLinkProperty.Trim()); }
            set { _ldapLinkProperty = value; }
        }

        [Browsable(true),
        Category("UsersADBrowser Parameters"),
        WebPartStorage(Storage.Shared),
        FriendlyName("List of names of organizational units that should be excluded (delimiter \",\")")]
        public string ExcludeOUs
        {
            get { return (_excludeOUs == "" ? "Domain Controllers,Trash" : _excludeOUs); }
            set { _excludeOUs = value; }
        }

        [Browsable(true),
        Category("UsersADBrowser Parameters"),
        WebPartStorage(Storage.Shared),
        FriendlyName("View mode")]
        public eViewMode ViewMode
        {
            get { return _vewMode; }
            set { _vewMode = value; }
        }

        [Browsable(true),
        Category("UsersADBrowser Parameters"),
        WebPartStorage(Storage.Shared),
        FriendlyName("User Info mode")]
        public eUserLinkMode UserLinkMode
        {
            get { return _linkMode; }
            set { _linkMode = value; }
        }

        [Browsable(true),
        Category("UsersADBrowser Parameters"),
        WebPartStorage(Storage.Shared),
        FriendlyName("Address of external page, that displays user info (only for User Info mode = ExternalPage)")]
        public string ExternalPageUrl
        {
            get { return _externalPageUrl; }
            set { _externalPageUrl = value; }
        }

        [Browsable(true),
        Category("UsersADBrowser Parameters"),
        WebPartStorage(Storage.Shared),
        FriendlyName("Show presence information (uses the status of Office Communicator)")]
        public bool IsShowPresence
        {
            get { return _isShowPresence; }
            set { _isShowPresence = value; }
        }

        [Browsable(true),
        Category("UsersADBrowser Parameters"),
        WebPartStorage(Storage.Shared),
        FriendlyName("Show the user photo")]
        public bool IsShowPhoto
        {
            get { return _isShowPhoto; }
            set { _isShowPhoto = value; }
        }

        [Browsable(true),
        Category("UsersADBrowser Parameters"),
        WebPartStorage(Storage.Shared),
        FriendlyName("Format of url of photos users")]
        public string ImageFormatUrl
        {
            get { return _imageFormatUrl; }
            set { _imageFormatUrl = value; }
        }

        [Browsable(true),
        Category("UsersADBrowser Parameters"),
        WebPartStorage(Storage.Shared),
        FriendlyName("Width of photos in list")]
        public int WidthImageList
        {
            get { return _imageListWidth; }
            set { _imageListWidth = value; }
        }

        [Browsable(true),
        Category("UsersADBrowser Parameters"),
        WebPartStorage(Storage.Shared),
        FriendlyName("Allow sorting")]
        public bool IsSorting
        {
            get { return _isSorting; }
            set { _isSorting = value; }
        }

        [Browsable(true),
        Category("UsersADBrowser Parameters"),
        WebPartStorage(Storage.Shared),
        FriendlyName("Caching time of organizational units (minutes)")]
        public int CachingTimeOU
        {
            get
            {
                return _cachingTimeOU;
            }
            set
            {
                _cachingTimeOU = value;
            }
        }

        [Browsable(true),
        Category("UsersADBrowser Parameters"),
        WebPartStorage(Storage.Shared),
        FriendlyName("Caching time of user list (minutes)")]
        public int CachingTimeUserList
        {
            get
            {
                return _cachingTimeUserList;
            }
            set
            {
                _cachingTimeUserList = value;
            }
        }

        public UsersADBrowserWP()
            : base()
        {
            WPDirName = _templateDirName;
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            TemplateFileName = _templateFileName;
        }

        protected override void InitControls(Control ctl)
        {
            CurrentWebPartManager.DisplayModeChanged += new WebPartDisplayModeEventHandler(WebPartManager_DisplayModeChanged);
            chSubTree = (CheckBox)GetControl(ctl, "chSubTree");
            chSubTree.CheckedChanged += new EventHandler(chSubTree_CheckedChanged);
            txtSearch = (TextBox)GetControl(ctl, "txtSearch");
            btnSearch = (ImageButton)GetControl(ctl, "btnSearch");
            btnSearch.Click += new ImageClickEventHandler(btnSearch_Click);
            btnExport = (LinkButton)GetControl(ctl, "btnExport");
            btnExport.Click += new EventHandler(btnExport_Click);
            phSplitterCode = (PlaceHolder)GetControl(ctl, "phSplitterCode");
            xmlOUTreeData = (XmlDataSource)GetControl(ctl, "xmlOUTreeData");
            xmlOUTreeData.EnableCaching = false;
            tvOU = (TreeView)GetControl(ctl, "tvOU");
            tvOU.TreeNodeDataBound += new TreeNodeEventHandler(tvOU_TreeNodeDataBound);
            dgUserList = (DataGrid)GetControl(ctl, "dgUserList");
            dgUserList.ItemDataBound += new DataGridItemEventHandler(dgUserList_ItemDataBound);
            dgUserList.PageIndexChanged += new DataGridPageChangedEventHandler(dgUserList_PageIndexChanged);
            dgUserList.ItemCreated += new DataGridItemEventHandler(dgUserList_ItemCreated);
            dgUserList.SortCommand += new DataGridSortCommandEventHandler(dgUserList_SortCommand);
            lblTotalValue = (Label)GetControl(ctl, "lblTotalValue");
            InitUserListGrid(dgUserList);
        }

        protected override void OnLoad(EventArgs e)
        {
            EnsureChildControls();

            strPathParam = Context.Request.QueryString["path"] != null ? Context.Request.QueryString["path"] : "";
            strSearchQuery = Context.Request.QueryString["q"] != null ? Context.Request.QueryString["q"] : "";

            if (!Page.IsPostBack)
            {
                FillTreeViewOU();
                FillUserList();
                if (strSearchQuery != "")
                {
                    txtSearch.Text = strSearchQuery;
                }
            }
        }

        protected override void OnPreRender(EventArgs e)
        {
            CheckViewMode();
        }

        private void FillTreeViewOU()
        {
            if (_vewMode == eViewMode.UserList)
                return;

            try
            {
                string[] arrExcludeNames = UsersADBrowserHelper.Values2Lower(ExcludeOUs.Split(','));
                string xmlOUData = "";
                string strCacheKey = UsersADBrowserHelper.GetMD5("UsersADBrowser.TreeViewOU." + LDAPStartPath + "." + ExcludeOUs + "." + _cachingTimeOU.ToString() + "." + this.ClientID);
                object objCache = HttpContext.Current.Cache[strCacheKey];

                if (objCache == null)
                {
                    xmlOUData = UsersADBrowserHelper.GetOUTreeDataFromAD(LDAPStartPath, arrExcludeNames, new StringBuilder());
                    HttpContext.Current.Cache.Insert(strCacheKey, xmlOUData, null, DateTime.Now.AddMinutes(_cachingTimeOU),
                                    Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
                }
                else
                {
                    xmlOUData = (string)objCache;
                }

                xmlOUTreeData.Data = "<items>" + xmlOUData + "</items>";
                xmlOUTreeData.DataBind();
                tvOU.DataSource = xmlOUTreeData;
                tvOU.DataBind();
                tvOU.CollapseAll();
                // find node by path
                if (strPathParam != "")
                {
                    TreeNode node = tvOU.FindNode(strPathParam);
                    node.Expand();
                    node.Select();
                    ExpandParents(node);
                }
            }
            catch (Exception ex)
            {
                WPException = "FillTreeViewOU error - " + ex.Message;
            }
        }

        private void ExpandParents(TreeNode item)
        {
            item.Expand();
            if (item.Parent != null)
            {
                ExpandParents(item.Parent);
            }
        }

        void tvOU_TreeNodeDataBound(object sender, TreeNodeEventArgs e)
        {
            e.Node.NavigateUrl = Context.Request.ServerVariables["SCRIPT_NAME"] + "?path=" + Context.Server.UrlEncode(e.Node.ValuePath);
        }

        private void InitUserListGrid(DataGrid dgUserList)
        {
            try
            {
                if (_isSorting)
                {
                    dgUserList.AllowSorting = true;
                    dgUserList.HeaderStyle.Wrap = false;
                }

                _arrProps = LDAPProperties.Replace(" ", "").Split(',');
                _arrPropsInLower = UsersADBrowserHelper.Values2Lower(_arrProps);
                BoundColumn colUserNum = new BoundColumn();
                colUserNum.Visible = false;
                colUserNum.DataField = "UserAccount";
                dgUserList.Columns.Add(colUserNum);

                if (_isShowPhoto)
                {
                    BoundColumn colUserPhoto = new BoundColumn();
                    colUserPhoto.DataField = "UserPhoto";
                    colUserPhoto.HeaderText = HttpContext.GetGlobalResourceObject(_resourceGlobalName, "UserPhoto").ToString();
                    dgUserList.Columns.Add(colUserPhoto);
                }

                if (_isShowPresence)
                {
                    BoundColumn colUserPresence = new BoundColumn();
                    colUserPresence.DataField = "UserPresence";
                    colUserPresence.HeaderText = "";
                    dgUserList.Columns.Add(colUserPresence);
                }

                for (int i = 0; i < _arrProps.Length; i++)
                {
                    BoundColumn colUserList = new BoundColumn();
                    colUserList.DataField = _arrProps[i];
                    colUserList.SortExpression = _arrProps[i];
                    try
                    {
                        colUserList.HeaderText = HttpContext.GetGlobalResourceObject(_resourceGlobalName, _arrProps[i]).ToString();
                    }
                    catch { }
                    dgUserList.Columns.Add(colUserList);
                }
            }
            catch (Exception ex)
            {
                WPException = "InitUserListGrid error - " + ex.Message;
            }
        }

        private void FillUserList()
        {
            try
            {
                string[] arrExcludeNames = UsersADBrowserHelper.Values2Lower(ExcludeOUs.Split(','));
                string strLdapPath = UsersADBrowserHelper.GetLdapPathFromRequest(strPathParam, LDAPStartPath, tvOU.PathSeparator);
                DataTable dtUserList = null;
                string strCacheKey = UsersADBrowserHelper.GetMD5("UsersADBrowser.UserList." + strLdapPath + "." + LDAPUsersFilter + "." + LDAPSortProperty + "." + LDAPProperties + "." + chSubTree.Checked.ToString() + "." + _isShowPhoto.ToString() + "." + _isShowPresence.ToString() + "." + ExcludeOUs + "." + _imageFormatUrl + "." + _isSorting.ToString() + "." + _cachingTimeUserList.ToString() + "." + this.ClientID);
                object objCache = HttpContext.Current.Cache[strCacheKey];

                if (objCache == null)
                {
                    dtUserList = UsersADBrowserHelper.GetUsersListFromAD(strLdapPath, LDAPUsersFilter, LDAPSortProperty, LDAPProperties.Replace(" ", "").Split(','), chSubTree.Checked,
                                                                            _isShowPhoto, _isShowPresence, arrExcludeNames);
                    HttpContext.Current.Cache.Insert(strCacheKey, dtUserList, null, DateTime.Now.AddMinutes(_cachingTimeUserList),
                                                        Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
                }
                else
                {
                    dtUserList = (DataTable)objCache;
                }

                string strSortDir = ViewState["sortUserList"] != null ? ViewState["sortUserList"].ToString() : "";

                if (strSearchQuery != "" || strSortDir != "")
                {
                    dtUserList = UsersADBrowserHelper.SearchUsersList(dtUserList, strSearchQuery, LDAPSortProperty, strSortDir);
                }

                dgUserList.DataSource = dtUserList;
                dgUserList.DataBind();

                dgUserList.PagerStyle.Visible = (dgUserList.PageCount <= 1 ? false : true);

                lblTotalValue.Text = dtUserList.DefaultView.Count.ToString();
            }
            catch (Exception ex)
            {
                WPException = "FillUserList error - " + ex.Message;
            }
        }

        void dgUserList_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                string strUserAccount = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "UserAccount"));

                int j = _isShowPhoto ? 2 : 1;

                // photo field
                if (_isShowPhoto)
                {
                    e.Item.Cells[1].Text = FieldTypeHelper.FormatImageField(strUserAccount, _imageFormatUrl, _imageListWidth);
                }

                // presence info field
                if (_isShowPresence)
                {
                    j = j + 1;
                    string strAddresses = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "UserPresence"));
                    string[] arrAddresses = strAddresses.Split(';');
                    string strUserSipAddress = UsersADBrowserHelper.GetSipAddressFromString(arrAddresses[0].Trim());
                    string strUserEmailAddress = arrAddresses[1].Trim();
                    string strUserAddress = "", type = "";
                    if (strUserSipAddress != "")
                    {
                        strUserAddress = strUserSipAddress;
                        type = "sip";
                    }
                    else if (strUserEmailAddress != "")
                    {
                        strUserAddress = strUserEmailAddress;
                        type = "smtp";
                    }

                    e.Item.Cells[j - 1].HorizontalAlign = HorizontalAlign.Center;
                    e.Item.Cells[j - 1].Text = FieldTypeHelper.FormatPresenceField(strUserAddress, type);
                }

                // format special attributes
                int idxField = Array.IndexOf(_arrPropsInLower, LDAPLinkProperty.ToLower());
                if (idxField != -1)
                {
                    string strLinkValue = Convert.ToString(DataBinder.Eval(e.Item.DataItem, LDAPLinkProperty));
                    e.Item.Cells[idxField + j].Text = FieldTypeHelper.FormatLinkField(strLinkValue, strUserAccount, ExternalPageUrl, _linkMode);
                }

                // email address
                idxField = Array.IndexOf(_arrPropsInLower, "mail");
                if (idxField != -1)
                {
                    string strUserEmail = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "mail"));
                    e.Item.Cells[idxField + j].Text = FieldTypeHelper.FormatEmailField(strUserEmail);
                }

                // manager
                idxField = Array.IndexOf(_arrPropsInLower, "manager");
                if (idxField != -1)
                {
                    string strUserManager = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "manager"));
                    e.Item.Cells[idxField + j].Text = FieldTypeHelper.FormatManagerField(strUserManager);
                }
            }
        }

        void dgUserList_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
        {
            dgUserList.CurrentPageIndex = e.NewPageIndex;
            FillUserList();
        }

        void dgUserList_ItemCreated(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Pager || e.Item.ItemType == ListItemType.Header)
            {
                foreach (Control ctrl in e.Item.Controls)
                {
                    foreach (Control ctl in ctrl.Controls)
                    {
                        if (ctl.GetType().ToString() == "System.Web.UI.WebControls.DataGridLinkButton")
                        {
                            LinkButton btn = (LinkButton)ctl;
                            btn.OnClientClick = "_spFormOnSubmitCalled = false;";
                        }
                    }
                }
            }
        }

        void dgUserList_SortCommand(object source, DataGridSortCommandEventArgs e)
        {
            ViewState["sortUserList"] = e.SortExpression;

            ShowHeaderSort(e.SortExpression);

            FillUserList();
        }

        private void ShowHeaderSort(string SortExp)
        {
            foreach (DataGridColumn column in dgUserList.Columns)
            {
                column.HeaderText = column.HeaderText.Replace("<img src=\"/_layouts/images/sort.gif\" border=0>", "");
                column.HeaderText = column.HeaderText.Replace("<img src=\"/_layouts/images/rsort.gif\" border=0>", "");
                if (column.SortExpression == SortExp)
                {
                    if (SortExp.IndexOf(" desc") != -1)
                    {
                        column.SortExpression = column.SortExpression.Replace(" desc", "");
                        column.HeaderText += "<img src=\"/_layouts/images/rsort.gif\" border=0>";
                    }
                    else
                    {
                        column.SortExpression += " desc";
                        column.HeaderText += "<img src=\"/_layouts/images/sort.gif\" border=0>";
                    }
                }
            }
        }

        void chSubTree_CheckedChanged(object sender, EventArgs e)
        {
            dgUserList.CurrentPageIndex = 0;
            FillUserList();
        }

        void btnSearch_Click(object sender, ImageClickEventArgs e)
        {
            string strQuery = txtSearch.Text.Trim();
            Context.Response.Redirect(Context.Request.ServerVariables["SCRIPT_NAME"] + "?q=" + Context.Server.UrlEncode(strQuery));
        }

        void btnExport_Click(object sender, EventArgs e)
        {
            try
            {
                FillUserList();
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=Export.xls");
                HttpContext.Current.Response.ContentType = "application/ms-excel";
                HttpContext.Current.Response.Charset = "utf-8";
                HttpContext.Current.Response.Write("<META HTTP-EQUIV=\"Content-Type\" content=\"text/html; charset=utf-8\">");

                StringBuilder sbExportData = new StringBuilder();

                using (DataGrid dgExport = new DataGrid())
                {
                    dgExport.ID = "dgExport";
                    dgExport.AutoGenerateColumns = false;
                    dgExport.ItemDataBound += new DataGridItemEventHandler(dgUserList_ItemDataBound);
                    InitUserListGrid(dgExport);
                    dgExport.DataSource = dgUserList.DataSource;
                    dgExport.DataBind();

                    sbExportData.Append("<table border=\"1\">");
                    int idxStart = 1 + (_isShowPhoto ? 1 : 0);
                    if (_isShowPresence)
                        idxStart = idxStart + 1;

                    sbExportData.Append("<tr>");
                    int i = 0;
                    foreach (DataGridColumn col in dgExport.Columns)
                    {
                        if (i >= idxStart)
                            sbExportData.Append("<th>" + col.HeaderText + "</th>");

                        i++;
                    }
                    sbExportData.Append("</tr>");

                    foreach (DataGridItem item in dgExport.Items)
                    {
                        if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                        {
                            sbExportData.Append("<tr>");

                            int j = 0;
                            foreach (TableCell cell in item.Cells)
                            {
                                if (j >= idxStart)
                                {
                                    sbExportData.Append("<td>");
                                    sbExportData.Append("\u00A0");
                                    sbExportData.Append(Regex.Replace(cell.Text, "<.*?>", string.Empty));
                                    sbExportData.Append("\u00A0");
                                    sbExportData.Append("</td>");
                                }
                                j++;
                            }

                            sbExportData.Append("</tr>");
                        }
                    }
                    sbExportData.Append("</table>");
                }

                HttpContext.Current.Response.Write(sbExportData.ToString());
                HttpContext.Current.Response.End();
            }
            catch { }
        }

        void WebPartManager_DisplayModeChanged(object sender, WebPartDisplayModeEventArgs e)
        {
            WebPartDisplayMode wpOldMode = e.OldDisplayMode;
            if (wpOldMode.Name == "Edit")
            {
                Context.Response.Redirect(Context.Request.ServerVariables["SCRIPT_NAME"]);
                /*
                dgUserList.Columns.Clear();
                InitUserListGrid(dgUserList);
                FillTreeViewOU();
                FillUserList();
                */
            }
        }

        private void CheckViewMode()
        {
            if (_vewMode == eViewMode.Full)
            {
                phSplitterCode.Visible = true;
                tvOU.Visible = true;
                chSubTree.Visible = true;
            }

            if (_vewMode == eViewMode.UserList)
            {
                phSplitterCode.Visible = false;
                tvOU.Visible = false;
                chSubTree.Visible = false;

                if (!this.Page.ClientScript.IsStartupScriptRegistered("UsersADBrowser_HideOUPanel"))
                {
                    string strJsCode = "if (document.getElementById('spltContainer')) {\r\n" +
                                        "document.getElementById('spltContainer').style.overflow = 'auto';}\r\n" +
                                        "if (document.getElementById('LeftPane')) {\r\n" +
                                        "document.getElementById('LeftPane').style.visibility = 'hidden';\r\n" +
                                        "document.getElementById('LeftPane').style.display = 'none';}";
                    this.Page.ClientScript.RegisterStartupScript(this.GetType(), "UsersADBrowser_HideOUPanel", "<script type=\"text/javascript\">" + strJsCode + "</script>");
                }
            }
        }

    }
}
